<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>登入</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/css/admin.css">
  <link rel="stylesheet" href="/js/layui/css/layui.css">
  <link rel="stylesheet" href="/css/login.css">
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

  <div class="layadmin-user-login-main">
    <div class="layadmin-user-login-box layadmin-user-login-header">
      <h2 style="color: #fff!important;">寻医路app Admin</h2>
    </div>
    <form class="layadmin-user-login-box layadmin-user-login-body layui-form">
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
        <input type="text" name="name" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
               class="layui-input">
      </div>
      <div class="layui-form-item">
        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
        <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码"
               class="layui-input">
      </div>
      <div class="layui-form-item">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登 入</button>
      </div>
    </form>
  </div>

  <div class="layui-trans layadmin-user-login-footer">

    <p>© 2020 <a href="javascript:;" target="_blank">成员管理系统</a></p>
  </div>

</div>

<script src="/js/layui/layui.js"></script>
<script type="text/javascript">

  layui.use(['form', 'layer'], function () {
    var form = layui.form
            , $ = layui.$
            , layer = layui.layer;
    setBackGround();
    form.render();

    form.on('submit(login)', function (obj) {
      $.post('/user/login', obj.field, function (res) {
        if (res.success) {
          layui.data('xunyilu', {
            key: 'token',
            value: res.payload.token
          })
          layer.msg('登录成功！', {icon: 6, time: 1200});
          const data = layui.data('xunyilu');

          location.href = '/admin/index?token=' + data.token;
        } else {
          layer.msg(res.msg, {icon: 5});
        }
      })
      return false;
    });

  });

  function setBackGround() {
    document.body.style.backgroundImage= "url(https://images.zhangyuxin.org.cn/)";
  }
</script>
</body>
</html>